package com.fyzk.activity.lottery.jc.football.newJz;

import android.view.Gravity;
import android.view.WindowManager;
import android.widget.PopupWindow;

import com.fyzk.activity.lottery.jc.football.JCZQ_BF_ZhiFuActivity;
import com.fyzk.activity.lottery.jc.football.adapter.JCZQ_BF_Adapter;
import com.fyzk.bean.JCZQResponseInfo;
import com.tyjc.lottery.R;
import com.fyzk.utils.LogUtil;
import com.fyzk.utils.LotteryIDUtils;
import com.fyzk.utils.ScreenUtils;
import com.fyzk.utils.Utils;

import java.util.List;

public class JCZQ_BF_Fragment extends JC_OpenPop_BaseFragment {

    private JCZQ_BF_Adapter adapter;

    @Override
    protected void initGameQueueView() {
        adapter = new JCZQ_BF_Adapter(getContext(), this, infos);
        center_list.setAdapter(adapter);
        for (int i = 0; i < adapter.getGroupCount(); i++) {
            center_list.expandGroup(i);
        }
        adapterChange(infos);
    }

    @Override
    protected void toZhanKai(int grouppostion, int position) {
        int height = Utils.dip2px(510f);
        BF_Sel_Pop bf_sel_pop = new BF_Sel_Pop(getContext(), WindowManager.LayoutParams
                .MATCH_PARENT, height, infos.get(grouppostion)
                .matchDatas.get(position));
        LogUtil.v("y=" + (ScreenUtils.getInstance().getHeight() - bf_sel_pop.getHeight()));
        LogUtil.v("p_height=" + bf_sel_pop.getHeight());
        setBackgroundAlpha(0.5f);
        bf_sel_pop.showAtLocation(getView(), Gravity.NO_GRAVITY, 0, ScreenUtils.getInstance()
                .getHeight() -
                height);
        bf_sel_pop.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {
                setBackgroundAlpha(1.0f);
                adapterChange(infos);
            }
        });

    }

    @Override
    protected void adapterChange(List<JCZQResponseInfo> infos) {
        super.adapterChange(infos);
        if (null != adapter) {
            adapter.setInfos(infos, 0);
            adapter.setCount(changCiNum);
        }
    }

    public void setBackgroundAlpha(float bgAlpha) {
        WindowManager.LayoutParams lp = getActivity().getWindow()
                .getAttributes();
        lp.alpha = bgAlpha;
        getActivity().getWindow().setAttributes(lp);
    }

    @Override
    protected int getLotteryType() {
        // TODO Auto-generated method stub
        return LotteryIDUtils.JZBF_LOTTERY_ID_INT;
    }

    @Override
    protected int getTitleStringRes() {
        // TODO Auto-generated method stub
        return R.string.jcz_bf;
    }

    @Override
    protected Class getZhiFuActivity() {
        // TODO Auto-generated method stub
        return JCZQ_BF_ZhiFuActivity.class;
    }


    @Override
    public void notifyList() {
        adapter.notifyDataSetChanged();
    }
}
